package cn.bdqn.controller;

import cn.bdqn.dao.IntegralMapper;
import cn.bdqn.pojo.Integral;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 刘旻昊
 * @Date: Created in 2020/6/22  19:10
 */
@org.springframework.stereotype.Controller
@RestController
public class IntegralController {
    @Resource
    IntegralMapper integralMapper;
    @GetMapping("/list3")
    public String list(Model model){
        List<Integral> list= integralMapper.listAll();
        model.addAttribute("list",list);
        return "list3";
    }

    @RequestMapping("/index3")
    public String index(Model model){
        List<Integral> list= integralMapper.listAll();
        model.addAttribute("list",list);
        return "index3";
    }
    @ResponseBody
    @RequestMapping("/delete/{id}3")
    public String del(@PathVariable("id") Integer id){
        Integer i=0;
        i= integralMapper.del(id);
        return i.toString();
    }

    @RequestMapping("/toadd3")
    public String add(){
        return "hello";
    }
    @RequestMapping("/add3")
    public String adds(Integral integral, Model model){
        Integer res= integralMapper.insert(integral);
        if (res>0){
            List<Integral> list= integralMapper.listAll();
            model.addAttribute("list",list);
            return "index3";
        }else{
            return "hello";
        }
    }

    @RequestMapping("/selectByid/{id}3")
    public String seleId(@PathVariable("id") Integer id, Model model){
        Integral list= integralMapper.listAllByid(id);
        model.addAttribute("list1",list);
        return "upd";
    }

    @RequestMapping("/upduser3")
    public String upd(Integral integral, Model model){
        Integer res= integralMapper.upd(integral);
        if (res>0){
            List<Integral> list= integralMapper.listAll();
            model.addAttribute("list",list);
            return "index3";
        }else{
            return "upd";
        }
    }
    /**
     * 签到
     * @return
     */
    //@ResponseBody
    @RequestMapping("/sign")
    public String getSign(){
        int staffid = 2;
        String text="签到";
        List<Integral> lists = integralMapper.getIntegrall(staffid,text);
//        System.out.println("asd"+lists);
        return "";
    }
}
